var vm = avalon.define({
	$id: "codebarManage",
	token:localData.get('token'),
	aplipaylist:[],
	sfbanklist:[],
	weixinlist:[],
	apliy: '',
	weixin:'',
	sfbank:'',
	showLoad:false,//是否显示load img
	sureClick:function(){
		if(vm.apliy == "" && vm.weixin == "" && vm.sfbank == ""){
			alert("必须选择其中一项扫码枪通道");
			return false;
		}
		vm.showLoad = true;
		postData(api_setinstanceforsweepcodepay, {
			token:vm.token,
			alipay:vm.apliy,
			weixin:vm.weixin,
			sfbank:vm.sfbank	
		}, function(res) {
			vm.showLoad = false;
			console.log(res);
			
			if (res.status == 'SUCCESS') {
	      alert("设置成功");
			} else {
				alert(res.msg);
			}
		});
		
	}
	
})
vm.$watch('onReady', function() {
	//扫码枪列表接口
	postData(api_getinstanceforsweepcodepay, {
		token: vm.token,
	}, function(res) {
		console.log(res);
		if (res.status == 'SUCCESS') {
			vm.aplipaylist = res.data[0].alipay;
			vm.sfbanklist = res.data[0].sfbank;
			vm.weixinlist = res.data[0].weixin;
		} else {
			alert(res.msg);
		}
		vm.weixinlist.forEach(function(elemet) {
			console.log(elemet);
			if (elemet.zdefault == 1) {
				vm.weixin = elemet.id;
			}
		});
		vm.aplipaylist.forEach(function(elemet) {
			console.log(elemet);
			if (elemet.zdefault == 1) {
				vm.apliy = elemet.id;
			}
		});
		vm.sfbanklist.forEach(function(elemet) {
			console.log(elemet);
			if (elemet.zdefault == 1) {
				vm.sfbank = elemet.id;
			}
		});
	});
})
